
layui.use(['form'], function () {

    var $ = layui.$, form = layui.form;
    $(function () {
        LoginStatus();
    })

    form.on('submit(btnSave)', function (data) {
        if (data.field.corporationCardImgPositive == '' || data.field.corporationCardImgPositive == null) {
            layerMsg("法人正面身份证照片不能为空!");
            return false;
        }
        if (data.field.corporationCardImgObverse == '' || data.field.corporationCardImgObverse == null) {
            layerMsg("法人反面身份证照片不能为空!");
            return false;
        }

        if (data.field.licenseImg == '' || data.field.licenseImg == null) {
            layerMsg("营业执照照片不能为空!");
            return false;
        }

        layer.load(2);
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: companyServices+"/company/corporation", // 需要提交的 url
            contentType:"application/json;charset=utf-8",
            xhrFields: {
                withCredentials: true
            }
            ,crossDomain: true
            ,data:JSON.stringify(data.field),
            success: function(res) {
                layer.closeAll('loading');
                if(res.status == '00200'){
                    layerMsg(res.message);
                    setTimeout(function() {
                        $.cookie('fullName','');
                        window.location.href="job-manage.html" ;
                    },2000);

                }else{
                    layerMsg(res.message)
                }
            },fail:function () {
                layer.closeAll('loading');
            }
        })


        return false;
    });


    //上传图片
    window.uploadImg = function(str, fileId, uploadId, imgId){

        var fileSize = $('#' + fileId)[0].files[0].size;
        var size = fileSize / 1024;
        if(size>5000){
            layerMsg("图片不超于5M");
            return false;
        }

        var file = $('#' + fileId).val();
        layer.load(2);
        var option = {
            type: 'post', // 提交方式 get/post
            url: companyServices+"/user/upload/img", // 需要提交的 url
            data: {
                'file': file,
            },
            success: function(res) {
                layer.closeAll('loading');
                var obj = JSON.parse(res);
                if(obj.code==0){
                    //    console.log(obj.data)
                    var fullPath = companyServices + obj.data.src;
                    $('#'+str).attr('src',fullPath);
                    $('#'+imgId).val(obj.data.src) ;
                    layerMsg(obj.msg);
                }
            }
        }
        $("#"+uploadId).ajaxSubmit(option);

    }



});